//
//  CustomTableViewCellTwo.m
//  ChunLaiZhuangClient
//
//  Created by zzs on 16/2/23.
//  Copyright © 2016年 CLZ. All rights reserved.
//

#import "CustomTableViewCellTwo.h"
#import "CustomMenuItem.h"
#import "MyCommentViewController.h"
#import "MyVoucherViewController.h"
#import "MyAttentionViewController.h"
#import "AppContext.h"
#import "AccountModel.h"
#import "LoginViewController.h"

@interface CustomTableViewCellTwo()
@property(nonatomic, strong) CustomMenuItem *wishItem;
@property(nonatomic, strong) CustomMenuItem *couponItem;
@property(nonatomic, strong) CustomMenuItem *reviewItem;

@end

@implementation CustomTableViewCellTwo

- (void)awakeFromNib {
    // Initialization code
    NSArray *titles=[NSArray arrayWithObjects:@"关注",@"优惠券",@"点评", nil];
    for (int i=0; i<3; i++) {
        UIView *lineView=[[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/3-1,27, 1,12)];
        lineView.backgroundColor=[UIColor colorWithHexString:@"D8D8D8"];
        CustomMenuItem *item=[[CustomMenuItem alloc] initWithFrame:CGRectMake(i*SCREEN_WIDTH/3,0,SCREEN_WIDTH/3, 65) num:@"0" name:titles[i]];
        item.tag=i;
        [item addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        switch (i) {
            case 0:{
                self.wishItem = item;
                [item addSubview:lineView];
            }
                break;
            case 1:{
                self.couponItem = item;
                [item addSubview:lineView];
            }
                break;
            case 2:{
                self.reviewItem = item;
            }
                break;
            default:
                break;
        }
        [self addSubview:item];
    }
    UIView *lineView=[[UIView alloc] initWithFrame:CGRectMake(0, 64.5, SCREEN_WIDTH, 0.5)];
    lineView.backgroundColor=[UIColor colorWithHexString:@"e1e1e1"];
    [self addSubview:lineView];
}
-(void)btnAction:(UIButton*)btn{
    switch (btn.tag) {
        case 0:
        {
            UIViewController *vc=[CustomTableViewCellTwo viewController:self];
            //关注
            if(!APP_CONTEXT.account) {
                [LoginViewController presentLoginViewController:vc withCompleteBlock:nil];
                return;
            }
            MyAttentionViewController *attentionVC=[[MyAttentionViewController alloc] init];
            [vc.navigationController pushViewController:attentionVC animated:YES];
            
        }
            break;
        case 1:
        {
            //优惠券
            UIViewController *vc=[CustomTableViewCellTwo viewController:self];
            if(!APP_CONTEXT.account) {
                [LoginViewController presentLoginViewController:vc withCompleteBlock:nil];
                return;
            }
            MyVoucherViewController *commentVC=[[MyVoucherViewController alloc] init];
            [vc.navigationController pushViewController:commentVC animated:YES];
        }
            break;
        case 2:
        {
            //点评
            UIViewController *vc=[CustomTableViewCellTwo viewController:self];
            if(!APP_CONTEXT.account) {
                [LoginViewController presentLoginViewController:vc withCompleteBlock:nil];
                return;
            }
            MyCommentViewController *commentVC=[[MyCommentViewController alloc] init];
            [vc.navigationController pushViewController:commentVC animated:YES];
            
        }
            break;
        default:
            break;
    }
}

- (void)updateNumInfo {
    if (APP_CONTEXT.account) {
        [self.wishItem updateNumLabel:APP_CONTEXT.account.data.wishlist_total];
        [self.couponItem updateNumLabel:APP_CONTEXT.account.data.coupon_valid];
        [self.reviewItem updateNumLabel:APP_CONTEXT.account.data.review_total];
    } else {
        [self.wishItem updateNumLabel:0];
        [self.couponItem updateNumLabel:0];
        [self.reviewItem updateNumLabel:0];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
